package com.runen.wnhz.runen.ui.adapter.puadapter;

import android.content.Context;
import android.support.v7.widget.LinearLayoutManager;
import android.support.v7.widget.RecyclerView;
import android.text.TextUtils;
import android.widget.ImageView;
import android.widget.RatingBar;

import com.chad.library.adapter.base.BaseQuickAdapter;
import com.chad.library.adapter.base.BaseViewHolder;
import com.runen.wnhz.runen.R;
import com.runen.wnhz.runen.common.utils.DisplayUtil;
import com.runen.wnhz.runen.common.utils.GlideUtils;
import com.runen.wnhz.runen.data.entity.MyOrderListBean;

/**
 * 描述：
 * 作者： 天天童话丶
 * 时间： 2018/6/1.
 */

public class MyOrderAdapter extends BaseQuickAdapter<MyOrderListBean.ListBean, BaseViewHolder> {
    private Context mContext;

    public MyOrderAdapter(Context context) {
        super(R.layout.item_mine_order, null);
        this.mContext = context;
    }

    @Override
    protected void convert(BaseViewHolder helper, MyOrderListBean.ListBean item) {
        String status;
        if (TextUtils.equals(item.getOrder_status(), "1")){
            status = "待支付";
            helper.setGone(R.id.item_mine_order_cancel_tv, true);
            helper.setGone(R.id.item_mine_order_pay_tv, true);
            helper.setGone(R.id.item_mine_order_goclass_tv, false);
        } else {
            status = "已支付";
            helper.setGone(R.id.item_mine_order_cancel_tv, false);
            helper.setGone(R.id.item_mine_order_pay_tv, false);
            helper.setGone(R.id.item_mine_order_goclass_tv, true);
        }

        helper.setText(R.id.item_mine_order_time_tv, item.getOrder_time())
                .setText(R.id.item_mine_order_no_tv, "订单：" + item.getOrder_no())
                .setText(R.id.item_mine_order_status_tv, status)
                .setText(R.id.item_mine_order_title_tv, item.getGoods_name())
                .setText(R.id.item_mine_order_aging_time_tv, "有效期：" + item.getAging_time())
                .setText(R.id.item_mine_order_price_tv, "￥ " + item.getTotal_fee());

        ImageView photoIv = helper.getView(R.id.item_mine_order_pic_iv);
        GlideUtils.getInstance().LoadContextRoundBitmap(mContext, item.getGoods_pic()
                , photoIv, DisplayUtil.dp2px(mContext, 2));

        if (item.getOtherList() != null && !item.getOtherList().isEmpty()) {
            helper.setGone(R.id.item_mine_order_data_ll, true);
            RecyclerView dataRv = helper.getView(R.id.item_mine_order_data_rv);
            dataRv.setLayoutManager(new LinearLayoutManager(mContext, LinearLayoutManager.HORIZONTAL, false));
//            dataRv.setAdapter(new MyOrderDataAdapter(mContext, item.getOtherList()));
        } else {
            helper.setGone(R.id.item_mine_order_data_ll, false);
        }

        if (!TextUtils.isEmpty(item.getStar())) {
            helper.setVisible(R.id.item_mine_order_score_tv, true);
            RatingBar ratingBar = helper.getView(R.id.item_mine_order_score_tv);
            ratingBar.setRating(Float.parseFloat(item.getStar()));
        } else {
            helper.setVisible(R.id.item_mine_order_score_tv, false);
        }

        helper.addOnClickListener(R.id.item_mine_order_cancel_tv);
        helper.addOnClickListener(R.id.item_mine_order_pay_tv);
        helper.addOnClickListener(R.id.item_mine_order_goclass_tv);
    }
}